<?php
namespace app\common\process;

class StoreSubsidiaryOne extends SubsidiaryOne {
    protected $ownerPk = 'sid';

     public function save($user) {
     	$this->event('after_save', function($row, $post) {
     		$ownerPk = $this->ownerPk;
     		$sid = $row[$ownerPk];
     		$store = loadModel('tysj\\Store')->find($sid);
     		$businessLicense = loadModel('tysj\\BusinessLicense')->where([$ownerPk => $sid])->find();
     		$corporation     = loadModel('tysj\\Corporation')->where([$ownerPk => $sid])->find();
     		$storeBank       = loadModel('tysj\\StoreBank')->where([$ownerPk => $sid])->find();

     		$examineEnum = loadEnum('StoreExamine');

               //一旦发生修改，如果信息满足就变为初审状态
     		if($store['examine'] == $examineEnum->code2key('daishenhe') && $businessLicense && $corporation && $storeBank) {
     			$store->examine = $examineEnum->code2key('chushen');
     			$store->save();
     		}
     	});
     	return parent::save($user);
     }
}